/*
  DuinolabButtonDim
  Turn on an LED when a button is pressed.  Control brightness of LED using pot.
  
  This example code is based on the Arduino Blink example.
 */

#include <Duinolab.h>
#include <Wire.h>      // need to get rid of this - Arduino IDE is too clever...

void setup() {
  // Initialize the Duinolab
  Duinolab.Init();
  
  // Connect LED 0 from the Duinolab  
  Duinolab.ConnectToArduino(LED_YELLOW);
  
  // Connect button 0
  Duinolab.ConnectToArduino(BUTTON_YELLOW);

  // Connect potentiometer 0
  Duinolab.ConnectToArduino(POT_BLACK);
}

void loop() {
  if (Duinolab.ButtonPressed(BUTTON_YELLOW)) {
    // pot is 0-1023, need 0-255 for brightness
    int brightness = Duinolab.ReadPot(POT_BLACK) >> 2;
    Duinolab.LEDOn(LED_YELLOW, brightness);   // set the LED on
  } else {
    Duinolab.LEDOff(LED_YELLOW);  // set the LED off
  }
}
